
import javax.microedition.lcdui.Graphics;

public final class UIKey {

    public int positionX;
    public int positionY;
    public int frameW;
    public int frameH;
    public int type;
    public static final int TYPE_W = 0;
    public static final int TYPE_B = 1;
    public boolean isPress;
    public int index;
    public String musicPath;
    UIMain uimain;

    public UIKey(int x, int y, int Type, int index) {
        this.index = index;
        this.positionX = x;
        this.positionY = y;

        this.type = Type;
        if (Type == 0) {
            this.frameW = R.key_white_normal.getWidth();
            this.frameH = R.key_white_normal.getHeight();

            this.musicPath = getNameByIndexW();
        } else {
            this.frameW = R.key_black_normal.getWidth();
            this.frameH = R.key_black_normal.getHeight();
            this.musicPath = getNameByIndexB();
        }
    }

    public void paint(Graphics g) {
        switch (this.type) {
            case 0:
                if (this.isPress) {
                    g.drawImage(R.key_white_press, this.positionX, this.positionY, 0);
                } else {
                    g.drawImage(R.key_white_normal, this.positionX, this.positionY, 0);
                }

                break;
            case 1:
                if (this.isPress) {
                    g.drawImage(R.key_black_press, this.positionX, this.positionY, 0);
                } else {
                    g.drawImage(R.key_black_normal, this.positionX, this.positionY, 0);
                }
                break;
        }
    }

    public boolean pointerPress(int x, int y) {
        if (L.isInRect(x, y, this.positionX, this.positionY, this.frameW, this.frameH)) {
            new SoundPlay(this.musicPath).play();

            UIMain.vecMusic.addElement(this.musicPath);
            this.isPress = true;
        }

        return this.isPress;
    }

    public String getNameByIndexB() {
        String path = null;
        if (this.index == 0) {
            path = "/c4m.mp3";
        }

        if (this.index == 1) {
            path = "/d4m.mp3";
        }
        if (this.index == 2) {
            path = "/f4m.mp3";
        }
        if (this.index == 3) {
            path = "/g4m.mp3";
        }
        if (this.index == 4) {
            path = "/a4m.mp3";
        }

        return path;
    }

    public String getNameByIndexW() {
        String path = null;
        if (this.index == 0) {
            path = "/c4.mp3";
        }

        if (this.index == 1) {
            path = "/d4.mp3";
        }
        if (this.index == 2) {
            path = "/e4.mp3";
        }
        if (this.index == 3) {
            path = "/f4.mp3";
        }
        if (this.index == 4) {
            path = "/g4.mp3";
        }
        if (this.index == 5) {
            path = "/a4.mp3";
        }
        if (this.index == 6) {
            path = "/b4.mp3";
        }
        return path;
    }

    public void pointerRelease(int x, int y) {
        this.isPress = false;
       
    }
}
